<?php

namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

class FileController extends BaseController
{
    /**
     * 上传
     * @param Request $request
     * @return JsonResponse
     */
    public function uploadFile(Request $request): JsonResponse
    {
        $file = $request->file('file');
        $date = date('Ymd',time());
        $name = $file->hashName();
        $storage_path = Config::get('filesystems.storage_path').'/'.$date.'/'.$name;
        $path = $this->upload($storage_path, $file);
        if (!$path){
            return $this->apiResult(['code'=>1,'message'=>'上传失败！']);
        }
        return $this->apiResult(['code'=>0,'data'=>$path,'message'=>'SUCCESS']);
    }
}
